package com.seocoo.worker.friend;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.TextView;

import com.google.gson.Gson;
import com.jaeger.library.StatusBarUtil;
import com.seocoo.worker.R;
import com.seocoo.worker.base.ImageLoaderEngine;
import com.seocoo.worker.base.widget.AppToolBer;
import com.seocoo.worker.base.widget.LtvRtvLayout;
import com.seocoo.worker.friend.entity.Friend;
import com.sfh.lib.ui.MVVMActivity;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * desc   : 工友详情
 * version: 1.0
 */
public class FriendDetailActivity extends MVVMActivity {


    private AppToolBer appToolBer;
    private CircleImageView ivPhoto;
    private TextView tvName;
    private TextView tvLevel;
    private TextView tvStatus;
    private LtvRtvLayout lvName;
    private LtvRtvLayout lvPhone;
    private LtvRtvLayout lvLevel;
    private LtvRtvLayout lvStatus;

    public static void start(Context context, Friend friend) {
        Intent intent = new Intent(context, FriendDetailActivity.class);
        intent.putExtra("data", new Gson().toJson(friend));
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.friend_detail_activity);
        initView();
        StatusBarUtil.setTransparentForImageView(this, appToolBer);
    }

    private void initView() {
        appToolBer = (AppToolBer) findViewById(R.id.appToolBer);
        ivPhoto = (CircleImageView) findViewById(R.id.iv_photo);
        tvName = (TextView) findViewById(R.id.tv_name);
        tvLevel = (TextView) findViewById(R.id.tv_level);
        tvStatus = (TextView) findViewById(R.id.tv_status);
        lvName = (LtvRtvLayout) findViewById(R.id.lv_name);
        lvPhone = (LtvRtvLayout) findViewById(R.id.lv_phone);
        lvLevel = (LtvRtvLayout) findViewById(R.id.lv_level);
        lvStatus = (LtvRtvLayout) findViewById(R.id.lv_status);

        Friend friend = new Gson().fromJson(getIntent().getStringExtra("data"), Friend.class);
        if (TextUtils.isEmpty(friend.getAvatar())) {
            ivPhoto.setImageResource(R.drawable.user_register);
        } else {
            new ImageLoaderEngine(friend.getAvatar()).error(R.drawable.user_register).placeholder(R.drawable.user_register).into(ivPhoto);
        }

        tvName.setText(friend.getRealName());
        lvName.getTvRight().setText(friend.getRealName());

        tvStatus.setText(friend.getTakeState());
        lvStatus.getTvRight().setText(friend.getTakeState());

        lvPhone.getTvRight().setText(friend.getPhoneNumber());
        lvLevel.getTvRight().setText(friend.getLevel() + "星");
        tvLevel.setText(friend.getLevel() + "");
    }
}
